
clear
clear all
clear mata
clear matrix
set more off
set matsize 11000
set maxvar 30000
cap log off
capture log close
set emptycells drop
pause on


***********************************************
* USER DEFINE FILEPATH FOR REPLICATION FOLDER *
***********************************************

global path "C:\Users\wb520443\Dropbox\Research Projects\Global pollution\2_analysis\Replication"



***********************************************


global opts		a f plain coll(none) nodep nomti c(b(star fmt(%9.3f)) se(abs par fmt(%9.3f))  ) star(* .10 ** .05 *** .01) noobs nocons

global opts_fs		a f plain coll(none) nodep nomti c(b(star fmt(%9.3f)) se(abs par fmt(%9.3f))) star(* .10 ** .05 *** .01) noobs nocons


global input "$path\data"
global figdat "$path\figdat"
global figures "$path\figures"
global tables "$path\tables"
		
	use "$input/rwi_pollution_analysis_collapsed.dta", replace
	
	
	encode country, g(country_code)
	
	
		
	
	g count=1
	
		
		
	reg mean_pm25 urca  if urca<8
		local urca11=_b[urca]
		local urca12=_b[_cons]
		
	reg mean_pm25 urca  if urca>7 & urca<15
		local urca21=_b[urca]
		local urca22=_b[_cons]
		
	reg mean_pm25 urca if urca>14
		local urca31=_b[urca]
		local urca32=_b[_cons]
		g urca3=urca*_b[urca] + _b[_cons] if urca>14
		
	preserve
		replace mean_pm25 = 102 if mean_pm25>102 & mean_pm25!=.
		g pm_round=round(mean_pm25)
		drop count
		rename population count
		
		collapse (sum) count (mean) population=count, by(pm_round urca)
		
		g urban=1 if urca<8
			replace urban=2 if urca>8 & urca<14
			replace urban=3 if urca>14
			
		
		bysort urban: egen total=total(count)
			replace count=count/total
			
		g urca1=urca*`urca11' + `urca12' if urca<8
		g urca2=urca*`urca21' + `urca22' if urca>7 & urca<15
		g urca3=urca*`urca31' + `urca32' if urca>14
		
		export delimited using "$figdat/urca_pm.csv", replace
		
		
	restore	
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		